#ifndef INDEXCOMPRESSOR_H_
#define INDEXCOMPRESSOR_H_

#include <fstream>
#include <vector>
#include <string.h>

using namespace std;

const int BUFFERLEN = 1024;
const int POSTFIXLEN = 16;
const int GOLOMBBASE = 16;

const int READMODE = 1;
const int WRITEMODE = 2;

enum EComprType {
  GAMMA, THETA, VGOLOMB, BYTECODEEX, ONEBYTECHAR, UNKNOWNTYPE
};

class IndexCompressor {
public:
  IndexCompressor();
  explicit IndexCompressor(EComprType type);
  ~IndexCompressor();

  int encode(int value, char* codeList, int &len, int& offset, EComprType type);
  int encode(int value, char* codeList, int &len, int& offset);

  int decode(const char* codeList, int &len, int &offset, EComprType type);
  int decode(const char* codeList, int &len, int &offset);

  int print_bits(const char* codeList, int len, int offset);

private:
  int write_uniry_bits(int bitNum, char* codeList, int &len, int& offset);
  int write_binary_bits(int value, int bitNum, char* codeList, int &len,
                        int& offset);

  int read_uniry_bits(const char* codeList, int &len, int&offset);
  int read_binary_bits(const char* codeList, int &len, int &offset, int bitsNum);

private:
  EComprType type_;
};

#endif
